package com.markedquilt.solution;
/*
 * PackageName: com.markedquilt.solution
 * ClassName:   IsPalindrome
 * Author:   zhang
 * Date:     Created in 2020/10/22
 * Description:
 * History:
 * <author>        <time>             <version>          <desc>
 * 作者姓名         修改时间            版本号              描述
 * zhang           2020/10/22      1.0
 */

/**
 * Title:
 * Project: LeetcodeProblem
 *
 * @author ZhangKe
 * Created on 2020/10/22
 */
public class num125IsPalidrome {
    public static boolean isPalindrome(String s) {
        char[] str = s.toCharArray();
        int length = str.length;
        if (!s.equals("") && s!=null){
            int head = 0,tail = length-1;
            for (int i = 0; head < tail; i++) {
                if (isLegal(str[head]) && isLegal(str[tail])){
                    if (!(str[head]+"").equalsIgnoreCase(str[tail]+""))
                        return false;
                    else{
                        head++;
                        tail--;
                    }
                }else{
                    if (!isLegal(str[head])){
                        head++;
                    }
                    if (!isLegal(str[tail])){
                        tail--;
                    }
                }
            }
            return true;
        }
        return true;
    }

    public static boolean isLegal(char str){
        if (('A' <= str && str<='Z') || ('a' <= str && str<='z') || ('0' <= str && str<='9'))
            return true;
        else
            return false;
    }

    public static void main(String[] args) {
        System.out.println(isPalindrome("A man, a plan, a canal: Panama"));
    }
}
